/*
-----------------------------------------------------------------------------
This source file is part of DIVA
The project of Engineering Lab, dept. of CSIE, NTNU.

Copyright (c) 2000-2006 The Engineering Lab, dept. of CSIE, NTNU.
-----------------------------------------------------------------------------
Filename:    MyWord.h
Description: 處理math node的不同型態的資料結構，為了簡化使用實作operator
			 overloading

-----------------------------------------------------------------------------
*/
#ifndef _MY_WORD_H_
#define _MY_WORD_H_

#include <string>
#include <vector>

class MyWord{

public:
	MyWord();
	/** 處理整數、浮點數、id以及運算元 */
	MyWord(std::string type,std::string value);
	/** 處理標點符號 */
	MyWord(std::string type);
	MyWord(MyWord& token);
	~MyWord();

	static int arithNumber;						//operator的個數
	static std::string ariths[];						//支援的operator
	static int ariths_num[];					//operator內部操作的個數如SUB(2,1)內部就是2個

	std::string _type;
	union{
		int _value_int;							//整數
		float _value_float;
		double _value_double;					//浮點數
	};
	std::string _value_string;						//ID

	std::vector<MyWord*>* _childs;

	//下面是operator overloading
	MyWord& operator +=(MyWord& token);
	MyWord& operator -=(MyWord& token);
	MyWord& operator *=(MyWord& token);
	MyWord& operator /=(MyWord& token);
	MyWord& operator +(MyWord& token);
	MyWord& operator -(MyWord& token);
	MyWord& operator -();
	MyWord& operator *(MyWord& token);
	MyWord& operator /(MyWord& token);
	MyWord& operator =(MyWord& token);

private:

	/** 由value決定型態，並初始化 */
	void normalize(std::string value);

	/** assert處理，目前只允許double、int */
	void typeCheck(MyWord* token);

};
#endif